package com.cinyi.cyds.base.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.beans.BeanUtils;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import com.cinyi.cyds.base.bean.ResourceType;
import com.cinyi.cyds.base.model.Tresourcetype;
import com.cinyi.cyds.base.service.ResourceTypeServiceI;
import com.cinyi.ormlite.web.dao.DefaultJdbcDaoImpl;


@Service
public class ResourceTypeServiceImpl implements ResourceTypeServiceI {
	private final static Logger logger = Logger.getLogger(ResourceTypeServiceImpl.class);
	
	private DefaultJdbcDaoImpl<Tresourcetype> resourceType ;

	public ResourceTypeServiceImpl(){
		resourceType =  new DefaultJdbcDaoImpl<Tresourcetype>();
	}
	@Override
	@Cacheable(value = "resourceTypeServiceCache", key = "'resourceTypeList'")
	public List<ResourceType> getResourceTypeList() throws Exception {
		List<Tresourcetype> l = resourceType.find(new Tresourcetype());
		List<ResourceType> rl = new ArrayList<ResourceType>();
		if (l != null && l.size() > 0) {
			for (Tresourcetype t : l) {
				ResourceType rt = new ResourceType();
				BeanUtils.copyProperties(t, rt);
				rl.add(rt);
			}
		}
		logger.info("getResourceTypeList:"+rl.size()) ;
		return rl;
	}

}
